package com.cskaoyan.config3;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/12/27 16:15
 */
@Configuration
@Data //主要是为了提供set方法 → 是为了给这些成员变量做赋值
@ConfigurationProperties(prefix = "cskaoyan.datasource3")
public class DataSourceConfiguration3 {
    String driverClassName;//前缀+成员变量名 cskaoyan.datasource3.driverClassName =配置文件中key

    String url;

    String username;

    String password;

    @Bean
    public DataSource dataSource3() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
